﻿using ManyToManyAgain.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations; //Used for AddOrUpdate()
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManyToManyAgain.Data
{
    /// <summary>
    /// A static class holding our Seed methods so we can choose what we want to seed, and what we don't.
    /// </summary>
    public static class Seeder
    {
        /// <summary>
        /// You can type in anything here and it will show on hover
        /// </summary>
        /// <param name="db">The Database Context</param>
        /// <param name="Songs">Seed Songs?</param>
        /// <param name="Albums">Seed Albums?</param>
        /// <param name="Album_Songs">Seed The Lookup Table?</param>
        public static void Seed(ApplicationDbContext db, bool Songs = true, bool Albums = true, bool Album_Songs = true)
        {
            if (Songs) SeedSongs(db);
            if (Albums) SeedAlbums(db);
            if (Album_Songs) SeedAlbum_Songs(db);
        }

        private static void SeedSongs(ApplicationDbContext db)
        {
            db.Songs.AddOrUpdate(x => x.SongId,
                new Song() { SongId = 1, Title = "First", DateReleased = DateTime.Now },
                new Song() { SongId = 2, Title = "Second", DateReleased = DateTime.Now },
                new Song() { SongId = 3, Title = "Third", DateReleased = DateTime.Now },
                new Song() { SongId = 4, Title = "Fourth", DateReleased = DateTime.Now },
                new Song() { SongId = 5, Title = "Fifth", DateReleased = DateTime.Now }
                );
        }

        private static void SeedAlbums(ApplicationDbContext db)
        {
            db.Albums.AddOrUpdate(x => x.AlbumId,
                new Album() { AlbumId = 1, Title = "First Album", Artist = "Random Artist" },
                new Album() { AlbumId = 2, Title = "Second Album", Artist = "Random Artist" },
                new Album() { AlbumId = 3, Title = "Best Hits", Artist = "Random Artist" }
                );
        }

        private static void SeedAlbum_Songs(ApplicationDbContext db)
        {
            db.AlbumSongs.AddOrUpdate(x => x.Albums_SongsId,
                new Albums_Songs() { Albums_SongsId = 1, AlbumId = 1, SongId = 1 },
                new Albums_Songs() { Albums_SongsId = 2, AlbumId = 1, SongId = 3 },
                new Albums_Songs() { Albums_SongsId = 3, AlbumId = 2, SongId = 2 },
                new Albums_Songs() { Albums_SongsId = 4, AlbumId = 2, SongId = 1 },
                new Albums_Songs() { Albums_SongsId = 5, AlbumId = 3, SongId = 1 },
                new Albums_Songs() { Albums_SongsId = 6, AlbumId = 3, SongId = 2 },
                new Albums_Songs() { Albums_SongsId = 7, AlbumId = 3, SongId = 3 }
                );
        }
    }
}